package com.example.questionnaires.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.questionnaires.entity.*;
import com.example.questionnaires.exception.BusinessException;
import com.example.questionnaires.mapper.*;
import com.example.questionnaires.service.QuestionnaireService;
import com.example.questionnaires.util.UserHolder;
import com.example.questionnaires.vo.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.questionnaires.common.PageResult;
import com.example.questionnaires.common.Result;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.time.LocalDateTime;
import java.time.LocalDate;

@Service
@Slf4j
public class QuestionnaireServiceImpl extends ServiceImpl<QuestionnaireMapper, Questionnaire> implements QuestionnaireService {
    @Autowired
    private QuestionMapper questionMapper;
    @Autowired
    private OptionMapper optionMapper;
    @Autowired
    private QuestionnaireRecordMapper recordMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private QuestionnaireMapper questionnaireMapper;

    @Override
    public List<Questionnaire> getLatest() {
        return list(new LambdaQueryWrapper<Questionnaire>()
                .eq(Questionnaire::getStatus, 1)
                .orderByDesc(Questionnaire::getCreateTime)
                .last("LIMIT 10"));
    }

    @Override
    public QuestionnaireDetailVO getDetail(Long id) {
        // 1. 获取问卷基本信息
        Questionnaire questionnaire = baseMapper.selectById(id);
        if (questionnaire == null) {
            throw new BusinessException("问卷不存在");
        }

        // 2. 获取问题列表
        List<Question> questions = questionMapper.selectList(
            new LambdaQueryWrapper<Question>()
                .eq(Question::getQuestionnaireId, id)
                .orderByAsc(Question::getSort)
        );

        // 3. 获取每个问题的选项
        List<QuestionVO> questionVOList = questions.stream().map(question -> {
            QuestionVO questionVO = new QuestionVO();
            BeanUtils.copyProperties(question, questionVO);

            // 如果是选择题，获取选项
            if (question.getType() == 1 || question.getType() == 2) {
                List<Option> options = optionMapper.selectList(
                    new LambdaQueryWrapper<Option>()
                        .eq(Option::getQuestionId, question.getId())
                        .orderByAsc(Option::getSort)
                );
                questionVO.setOptions(options);
            }

            return questionVO;
        }).collect(Collectors.toList());

        // 4. 组装返回数据
        QuestionnaireDetailVO detailVO = new QuestionnaireDetailVO();
        BeanUtils.copyProperties(questionnaire, detailVO);
        detailVO.setQuestions(questionVOList);

        return detailVO;
    }

    @Override
    @Transactional
    public void saveDetail(QuestionnaireDetailVO questionnaireDetail) {
        // 保存问卷基本信息
        Questionnaire questionnaire = new Questionnaire();
        BeanUtils.copyProperties(questionnaireDetail, questionnaire);
        saveOrUpdate(questionnaire);

        // 删除原有问题和选项
        questionMapper.delete(new LambdaQueryWrapper<Question>()
                .eq(Question::getQuestionnaireId, questionnaire.getId()));
        // 由于设置了外键级联删除，选项会自动删除

        // 保存新的问题和选项
        for (QuestionVO questionVO : questionnaireDetail.getQuestions()) {
            Question question = new Question();
            BeanUtils.copyProperties(questionVO, question);
            question.setQuestionnaireId(questionnaire.getId());
            questionMapper.insert(question);

            if (questionVO.getOptions() != null) {
                for (Option option : questionVO.getOptions()) {
                    option.setQuestionId(question.getId());
                    optionMapper.insert(option);
                }
            }
        }
    }

    @Override
    @Transactional
    public void submitAnswer(Long id, String answers) {
        try {
            // 1. 检查问卷是否存在且已发布
            Questionnaire questionnaire = baseMapper.selectById(id);
            if (questionnaire == null) {
                throw new BusinessException("问卷不存在");
            }
            if (questionnaire.getStatus() != 1) {
                throw new BusinessException("问卷未发布或已结束");
            }

            // 2. 获取当前用户
            User user = UserHolder.getUser(); // 如果未登录会抛出异常
            if (user == null) {
                throw new BusinessException("请先登录");
            }

            // 3. 检查是否已经提交过
            Long count = recordMapper.selectCount(
                new LambdaQueryWrapper<QuestionnaireRecord>()
                    .eq(QuestionnaireRecord::getQuestionnaireId, id)
                    .eq(QuestionnaireRecord::getUserId, user.getId())
            );
            if (count > 0) {
                throw new BusinessException("您已经提交过该问卷");
            }

            // 4. 保存答案
            QuestionnaireRecord record = new QuestionnaireRecord();
            record.setQuestionnaireId(id);
            record.setUserId(user.getId());
            record.setAnswers(answers);
            recordMapper.insert(record);
        } catch (BusinessException e) {
            throw e;
        } catch (Exception e) {
            log.error("提交问卷答案失败", e);
            throw new BusinessException("提交失败：" + e.getMessage());
        }
    }

    @Override
    public StatisticsVO getStatistics() {
        StatisticsVO vo = new StatisticsVO();
        try {
            // 设置统计数据
            vo.setTotalQuestionnaires(count(new LambdaQueryWrapper<Questionnaire>()
                .eq(Questionnaire::getStatus, 1)));

            vo.setTotalUsers(userMapper.selectCount(new LambdaQueryWrapper<User>()
                .eq(User::getStatus, 1)));

            LocalDateTime today = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
            vo.setTodaySubmissions(recordMapper.selectCount(new LambdaQueryWrapper<QuestionnaireRecord>()
                .ge(QuestionnaireRecord::getCreateTime, today)));

            vo.setTotalSubmissions(recordMapper.selectCount(null));

            // 获取最近7天的统计数据
            List<DailyStatVO> dailyStats = new ArrayList<>();
            LocalDate now = LocalDate.now();
            for (int i = 6; i >= 0; i--) {
                LocalDate date = now.minusDays(i);
                LocalDateTime start = date.atStartOfDay();
                LocalDateTime end = date.plusDays(1).atStartOfDay();

                DailyStatVO dailyStat = new DailyStatVO();
                dailyStat.setDate(date);
                dailyStat.setSubmissions(recordMapper.selectCount(new LambdaQueryWrapper<QuestionnaireRecord>()
                    .between(QuestionnaireRecord::getCreateTime, start, end)));
                dailyStat.setViews(0L); // 浏览量需要另外实现

                dailyStats.add(dailyStat);
            }
            vo.setDailyStats(dailyStats);

            return vo;
        } catch (Exception e) {
            log.error("获取统计数据失败", e);
            throw new BusinessException("获取统计数据失败");
        }
    }

    @Override
    public QuestionnaireStatisticsVO getQuestionnaireStatistics(Long id) {
        Questionnaire questionnaire = super.getById(id);
        if (questionnaire == null) {
            throw new BusinessException("问卷不存在");
        }

        // 获取问题列表
        List<Question> questions = questionMapper.selectList(
            new LambdaQueryWrapper<Question>()
                .eq(Question::getQuestionnaireId, id)
                .orderByAsc(Question::getSort)
        );

        // 获取选项列表
        List<Long> questionIds = questions.stream().map(Question::getId).collect(Collectors.toList());
        List<Option> options = CollUtil.isEmpty(questionIds) ? new ArrayList<>() : optionMapper.selectList(
            new LambdaQueryWrapper<Option>()
                .in(Option::getQuestionId, questionIds)
                .orderByAsc(Option::getSort)
        );

        // 获取所有答案记录
        List<QuestionnaireRecord> records = recordMapper.selectList(
            new LambdaQueryWrapper<QuestionnaireRecord>()
                .eq(QuestionnaireRecord::getQuestionnaireId, id)
        );

        // 统计结果
        QuestionnaireStatisticsVO result = new QuestionnaireStatisticsVO();
        result.setId(questionnaire.getId());
        result.setTitle(questionnaire.getTitle());
        result.setDescription(questionnaire.getDescription());
        result.setTotalSubmissions((long) records.size());

        // 按问题统计
        List<QuestionStatisticsVO> questionStats = new ArrayList<>();
        Map<Long, List<Option>> questionOptionsMap = options.stream()
            .collect(Collectors.groupingBy(Option::getQuestionId));

        for (Question question : questions) {
            QuestionStatisticsVO questionStat = new QuestionStatisticsVO();
            questionStat.setId(question.getId());
            questionStat.setTitle(question.getTitle());
            questionStat.setType(question.getType());
            questionStat.setTotalAnswers((long) records.size());

            // 统计答案
            if (question.getType() == 3) { // 填空题
                List<String> textAnswers = new ArrayList<>();
                Map<String, Long> wordCloud = new HashMap<>();

                for (QuestionnaireRecord record : records) {
                    JSONObject answers = JSON.parseObject(record.getAnswers());
                    String answer = answers.getString("q" + question.getId());
                    if (StrUtil.isNotBlank(answer)) {
                        textAnswers.add(answer);
                        // 简单分词统计
                        String[] words = answer.split("[\\s,，。.!！?？]");
                        for (String word : words) {
                            if (StrUtil.isNotBlank(word)) {
                                wordCloud.merge(word, 1L, Long::sum);
                            }
                        }
                    }
                }

                questionStat.setTextAnswers(textAnswers);
                questionStat.setWordCloud(wordCloud);
            } else { // 选择题
                List<Option> questionOptions = questionOptionsMap.getOrDefault(question.getId(), new ArrayList<>());
                Map<Long, Long> optionCountMap = new HashMap<>();

                for (QuestionnaireRecord record : records) {
                    JSONObject answers = JSON.parseObject(record.getAnswers());
                    if (question.getType() == 1) { // 单选题
                        Long optionId = answers.getLong("q" + question.getId());
                        if (optionId != null) {
                            optionCountMap.merge(optionId, 1L, Long::sum);
                        }
                    } else { // 多选题
                        List<Long> optionIds = answers.getJSONArray("q" + question.getId())
                            .toJavaList(Long.class);
                        if (CollUtil.isNotEmpty(optionIds)) {
                            for (Long optionId : optionIds) {
                                optionCountMap.merge(optionId, 1L, Long::sum);
                            }
                        }
                    }
                }

                List<OptionStatisticsVO> optionStats = new ArrayList<>();
                for (Option option : questionOptions) {
                    OptionStatisticsVO optionStat = new OptionStatisticsVO();
                    optionStat.setId(option.getId());
                    optionStat.setContent(option.getContent());
                    long count = optionCountMap.getOrDefault(option.getId(), 0L);
                    optionStat.setCount(count);
                    optionStat.setPercentage(records.isEmpty() ? 0.0 : count / (double) records.size());
                    optionStats.add(optionStat);
                }
                questionStat.setOptions(optionStats);
            }

            questionStats.add(questionStat);
        }

        result.setQuestions(questionStats);
        return result;
    }

    @Override
    public Result<PageResult<Questionnaire>> list(Integer page, Integer size) {
        // 创建分页参数
        Page<Questionnaire> pageParam = new Page<>(page, size);
        
        // 构建查询条件
        LambdaQueryWrapper<Questionnaire> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Questionnaire::getCreateTime);
        
        // 执行分页查询
        Page<Questionnaire> result = questionnaireMapper.selectPage(pageParam, wrapper);
        
        // 构建返回结果
        PageResult<Questionnaire> pageResult = new PageResult<>(
            result.getRecords(),
            result.getTotal(),
            result.getSize(),
            result.getCurrent()
        );
        
        return Result.success(pageResult);
    }

    @Override
    @Transactional
    public Result<Void> add(Questionnaire questionnaire) {
        log.info("开始添加问卷: {}", questionnaire);
        try {
            // 设置创建者ID
            User user = UserHolder.getUser();
            questionnaire.setCreatorId(user.getId());

            // 设置初始状态
            questionnaire.setStatus(0);  // 0: 未发布

            // 设置创建时间和更新时间
            LocalDateTime now = LocalDateTime.now();
            questionnaire.setCreateTime(now);
            questionnaire.setUpdateTime(now);

            // 保存问卷
            save(questionnaire);

            // 保存问题和选项
            if (questionnaire.getQuestions() != null) {
                for (Question question : questionnaire.getQuestions()) {
                    question.setQuestionnaireId(questionnaire.getId());
                    question.setCreateTime(now);
                    question.setUpdateTime(now);
                    questionMapper.insert(question);

                    // 如果是选择题，保存选项
                    if ((question.getType() == 1 || question.getType() == 2) && question.getOptions() != null) {
                        for (Option option : question.getOptions()) {
                            option.setQuestionId(question.getId());
                            option.setCreateTime(now);
                            option.setUpdateTime(now);
                            optionMapper.insert(option);
                        }
                    }
                }
            }

            log.info("添加问卷成功, id: {}", questionnaire.getId());
            return Result.success();
        } catch (Exception e) {
            log.error("添加问卷失败", e);
            return Result.error("添加问卷失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional
    public Result<Void> update(Questionnaire questionnaire) {
        log.info("开始更新问卷: {}", questionnaire);
        try {
            // 验证权限
            Questionnaire old = baseMapper.selectById(questionnaire.getId());
            if (old == null) {
                return Result.error("问卷不存在");
            }

            User user = UserHolder.getUser();
            // 只有管理员和问卷创建者可以修改
            if (!user.getRole().equals(1) && !user.getId().equals(old.getCreatorId())) {
                return Result.error("无权修改此问卷");
            }

            // 已发布的问卷不能修改
            if (old.getStatus() != 0) {
                return Result.error("已发布的问卷不能修改");
            }

            // 设置更新时间
            LocalDateTime now = LocalDateTime.now();
            questionnaire.setUpdateTime(now);

            // 保持原有字段不变
            questionnaire.setCreatorId(old.getCreatorId());
            questionnaire.setCreateTime(old.getCreateTime());
            questionnaire.setStatus(old.getStatus());

            // 更新问卷
            updateById(questionnaire);

            // 删除原有问题和选项
            questionMapper.delete(new LambdaQueryWrapper<Question>()
                .eq(Question::getQuestionnaireId, questionnaire.getId()));
            // 由于设置了外键级联删除，选项会自动删除

            // 保存新的问题和选项
            if (questionnaire.getQuestions() != null) {
                for (Question question : questionnaire.getQuestions()) {
                    // 清除问题ID，让数据库自动生成
                    question.setId(null);
                    question.setQuestionnaireId(questionnaire.getId());
                    question.setCreateTime(now);
                    question.setUpdateTime(now);
                    questionMapper.insert(question);

                    // 如果是选择题，保存选项
                    if ((question.getType() == 1 || question.getType() == 2) && question.getOptions() != null) {
                        for (Option option : question.getOptions()) {
                            // 清除选项ID，让数据库自动生成
                            option.setId(null);
                            option.setQuestionId(question.getId());
                            option.setCreateTime(now);
                            option.setUpdateTime(now);
                            optionMapper.insert(option);
                        }
                    }
                }
            }

            log.info("更新问卷成功");
            return Result.success();
        } catch (Exception e) {
            log.error("更新问卷失败", e);
            return Result.error("更新问卷失败: " + e.getMessage());
        }
    }

    @Override
    public Result<Void> delete(Long id) {
        log.info("开始删除问卷, id: {}", id);
        try {
            Questionnaire questionnaire = baseMapper.selectById(id);
            if (questionnaire == null) {
                return Result.error("问卷不存在");
            }

            User user = UserHolder.getUser();
            // 只有管理员和问卷创建者可以删除
            if (!user.getRole().equals(1) && !user.getId().equals(questionnaire.getCreatorId())) {
                return Result.error("无权删除此问卷");
            }

            // 已发布的问卷不能删除
            if (questionnaire.getStatus() != 0) {
                return Result.error("已发布的问卷不能删除");
            }

            removeById(id);
            log.info("删除问卷成功");
            return Result.success();
        } catch (Exception e) {
            log.error("删除问卷失败", e);
            return Result.error("删除问卷失败: " + e.getMessage());
        }
    }

    @Override
    public Result<Void> publish(Long id) {
        log.info("开始发布问卷, id: {}", id);
        try {
            Questionnaire questionnaire = baseMapper.selectById(id);
            if (questionnaire == null) {
                return Result.error("问卷不存在");
            }

            User user = UserHolder.getUser();
            // 只有管理员和问卷创建者可以发布
            if (!user.getRole().equals(1) && !user.getId().equals(questionnaire.getCreatorId())) {
                return Result.error("无权发布此问卷");
            }

            // 已发布或已结束的问卷不能再次发布
            if (questionnaire.getStatus() != 0) {
                return Result.error("问卷状态不正确，无法发布");
            }

            questionnaire.setStatus(1);
            updateById(questionnaire);
            log.info("发布问卷成功");
            return Result.success();
        } catch (Exception e) {
            log.error("发布问卷失败", e);
            return Result.error("发布问卷失败: " + e.getMessage());
        }
    }

    @Override
    public Result<Void> end(Long id) {
        log.info("开始结束问卷, id: {}", id);
        try {
            Questionnaire questionnaire = baseMapper.selectById(id);
            if (questionnaire == null) {
                return Result.error("问卷不存在");
            }

            User user = UserHolder.getUser();
            // 只有管理员和问卷创建者可以结束
            if (!user.getRole().equals(1) && !user.getId().equals(questionnaire.getCreatorId())) {
                return Result.error("无权结束此问卷");
            }

            // 只有已发布的问卷可以结束
            if (questionnaire.getStatus() != 1) {
                return Result.error("问卷状态不正确，无法结束");
            }

            questionnaire.setStatus(2);
            updateById(questionnaire);
            log.info("结束问卷成功");
            return Result.success();
        } catch (Exception e) {
            log.error("结束问卷失败", e);
            return Result.error("结束问卷失败: " + e.getMessage());
        }
    }

    @Override
    public Map<String, Object> getQuestionnaireWithAnswers(Long id) {
        // 获取问卷基本信息
        Questionnaire questionnaire = baseMapper.selectById(id);
        if (questionnaire == null) {
            throw new RuntimeException("问卷不存在");
        }

        // 获取问题列表
        List<Question> questions = questionMapper.selectList(
            new LambdaQueryWrapper<Question>()
                .eq(Question::getQuestionnaireId, id)
                .orderByAsc(Question::getSort)
        );

        // 获取每个问题的选项
        for (Question question : questions) {
            List<Option> options = optionMapper.selectList(
                new LambdaQueryWrapper<Option>()
                    .eq(Option::getQuestionId, question.getId())
                    .orderByAsc(Option::getSort)
            );
            question.setOptions(options);
        }

        // 组装返回数据
        Map<String, Object> result = new HashMap<>();
        result.put("id", questionnaire.getId());
        result.put("title", questionnaire.getTitle());
        result.put("description", questionnaire.getDescription());
        result.put("status", questionnaire.getStatus());
        result.put("questions", questions);

        return result;
    }

    @Override
    public List<QuestionnaireSubmissionVO> getMySubmissions() {
        // 1. 获取当前用户
        User user = UserHolder.getUser();

        // 2. 查询该用户的所有提交记录
        List<QuestionnaireRecord> records = recordMapper.selectList(
            new LambdaQueryWrapper<QuestionnaireRecord>()
                .eq(QuestionnaireRecord::getUserId, user.getId())
                .eq(QuestionnaireRecord::getDeleted, false)
                .orderByDesc(QuestionnaireRecord::getCreateTime)
        );

        // 3. 转换为VO
        return records.stream().map(record -> {
            QuestionnaireSubmissionVO vo = new QuestionnaireSubmissionVO();
            // 获取问卷信息
            Questionnaire questionnaire = baseMapper.selectById(record.getQuestionnaireId());
            if (questionnaire != null) {
                vo.setId(questionnaire.getId());
                vo.setQuestionnaireId(record.getQuestionnaireId());
                vo.setTitle(questionnaire.getTitle());
                vo.setDescription(questionnaire.getDescription());
            }
            vo.setSubmitTime(record.getCreateTime());
            vo.setAnswers(record.getAnswers());
            return vo;
        }).collect(Collectors.toList());
    }

    @Override
    public void submitQuestionnaire(Long id, Map<String, Object> answers) {
        // 1. 检查问卷是否存在且已发布
        Questionnaire questionnaire = baseMapper.selectById(id);
        if (questionnaire == null) {
            throw new BusinessException("问卷不存在");
        }
        if (questionnaire.getStatus() != 1) {
            throw new BusinessException("问卷未发布或已结束");
        }

        // 2. 获取当前用户
        User user = UserHolder.getUser();
        if (user == null) {
            throw new BusinessException("请先登录");
        }

        // 3. 检查是否已经提交过
        Long count = recordMapper.selectCount(
            new LambdaQueryWrapper<QuestionnaireRecord>()
                .eq(QuestionnaireRecord::getQuestionnaireId, id)
                .eq(QuestionnaireRecord::getUserId, user.getId())
        );
        if (count > 0) {
            throw new BusinessException("您已经提交过该问卷");
        }

        // 4. 保存答案
        QuestionnaireRecord record = new QuestionnaireRecord();
        record.setQuestionnaireId(id);
        record.setUserId(user.getId());
        record.setAnswers(JSON.toJSONString(answers));
        recordMapper.insert(record);
    }

    @Override
    public QuestionnaireRecord getSubmissionByQuestionnaireId(Long questionnaireId, Long userId) {
        return recordMapper.selectOne(
            new LambdaQueryWrapper<QuestionnaireRecord>()
                .eq(QuestionnaireRecord::getQuestionnaireId, questionnaireId)
                .eq(QuestionnaireRecord::getUserId, userId)
                .eq(QuestionnaireRecord::getDeleted, false)
                .orderByDesc(QuestionnaireRecord::getCreateTime)
                .last("LIMIT 1")
        );
    }

    @Override
    public QuestionnaireVO getQuestionnaireDetail(Long id) {
        // 1. 获取问卷信息
        Questionnaire questionnaire = getById(id);
        if (questionnaire == null) {
            throw new BusinessException("问卷不存在");
        }

        // 2. 增加浏览量
        questionnaire.setViewCount(questionnaire.getViewCount() + 1);
        updateById(questionnaire);

        // 3. 获取问题列表
        List<Question> questions = questionMapper.selectList(
            new LambdaQueryWrapper<Question>()
                .eq(Question::getQuestionnaireId, id)
                .orderByAsc(Question::getSort)
        );

        // 4. 获取每个问题的选项
        for (Question question : questions) {
            if (question.getType() == 1 || question.getType() == 2) { // 单选或多选题
                List<Option> options = optionMapper.selectList(
                    new LambdaQueryWrapper<Option>()
                        .eq(Option::getQuestionId, question.getId())
                        .orderByAsc(Option::getSort)
                );
                question.setOptions(options);
            }
        }

        // 5. 转换为VO
        QuestionnaireVO vo = new QuestionnaireVO();
        BeanUtils.copyProperties(questionnaire, vo);
        vo.setQuestions(questions);

        return vo;
    }

    @Override
    public Result<QuestionnaireVO> getQuestionnaire(Long id) {
        try {
            QuestionnaireVO vo = getQuestionnaireDetail(id);
            return Result.success(vo);
        } catch (BusinessException e) {
            return Result.error(e.getMessage());
        } catch (Exception e) {
            log.error("获取问卷详情失败", e);
            return Result.error("获取问卷详情失败: " + e.getMessage());
        }
    }

    private QuestionnaireVO convertToVO(Questionnaire questionnaire) {
        if (questionnaire == null) {
            return null;
        }
        QuestionnaireVO vo = new QuestionnaireVO();
        BeanUtils.copyProperties(questionnaire, vo);
        return vo;
    }

    private PageResult<QuestionnaireVO> convertToPageResult(Page<Questionnaire> page) {
        if (page == null) {
            return null;
        }
        List<QuestionnaireVO> records = page.getRecords().stream()
            .map(this::convertToVO)
            .collect(Collectors.toList());
        
        return new PageResult<>(
            records,
            page.getTotal(),
            page.getSize(),
            page.getCurrent()
        );
    }
}
